package cn.hk.controller;

import cn.HK.vo.SystemResult;
import cn.hk.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class CheckController {
    @Autowired
    private CheckService checkService;
    /*
            用户名重复校验
            请求路径	/user/checkName
            请求方式	get
            请求参数	userName
            返回值类型SystemResult

     */
    @RequestMapping(value ="/checkName",method = RequestMethod.GET)
    public SystemResult checkUsername(String uName) {
        boolean available =checkService.checkUsername(uName);
        if (available) {
            return SystemResult.ok();//可用,不存在
        } else {
            return SystemResult.build
                    (201, "用户名已经存在", null);
        }
    }
}
